/**
 * Test cases for change tracker.
 */
dojo.provide("test.dataset.changeTracker");

dojo.require("doh.runner");
dojo.require("spaghetti.dataset.changeTracker");

setUp = function(){
	//	The mock record.
	this.mockRecord = {
	};
	
	// The mock dataset
	this.dataset = {
		onRecordAdd : function(record, index){	
		},
		
		onRecordRemove : function(record){
		},
		
		onRecordChange : function(record, property, oldValue, newValue){
		}
	};
	
	// Mixin the tracker and initialize it.
	dojo.mixin(this.dataset, new spaghetti.dataset.ChangeTracker());
	this.dataset.initTrack();
	
	console.info("Setting up " + this.name);
}

tearDown = function(){
	console.info("Tearing down " + this.name);
}

doh.register("ChangeTracker Test Cases", [
{
	name : "Test Tracker",
	setUp : setUp,
	runTest : function(){
		//	First add it.
		this.dataset.onRecordAdd(this.mockRecord, 0);
		doh.t(this.dataset.getChanges(this.mockRecord).add);
		//	Then change it.
		this.dataset.onRecordChange(this.mockRecord, "test", 1, 2);
		var changes = this.dataset.getChanges(this.mockRecord);
		doh.t(changes.change.test.first);
		doh.is(changes.change.test.first.oldValue, 1);
		//	Change it again.
		this.dataset.onRecordChange(this.mockRecord, "test", 2, 3);
		doh.t(changes.change.test.last);
		doh.is(changes.change.test.last.oldValue, 2);
		//	Change it again.
		this.dataset.onRecordChange(this.mockRecord, "test", 3, 4);
		doh.t(changes.change.test.last);
		doh.is(changes.change.test.last.oldValue, 3);
		doh.t(changes.change.test.first);
		doh.is(changes.change.test.first.oldValue, 1);
		//	Then Delete it
		this.dataset.onRecordRemove(this.mockRecord);
		doh.t(this.dataset.getChanges(this.mockRecord).remove);
	},
	tearDown : tearDown
}
]);